﻿using MaterialDesignThemes.Wpf;
using Module.Common.Properties;
using Prism.Mvvm;

namespace Module.Common.ViewModels
{
    /// <summary>
    /// 软件设置
    /// </summary>
    public class SystemOptionViewModel : BindableBase
    {
        public SystemOptionViewModel()
        {
            IsDarkMode = Settings.Default.IsDarkTheme; // 获取用户设置
            IsShowMovePoint = Settings.Default.IsShowMovePoint;
        }

        private bool _isDarkMode;  // 窗口主题，true=深色，false=浅色
        public bool IsDarkMode
        {
            get { return _isDarkMode; }
            set
            {
                SetProperty(ref _isDarkMode, value);
                ModifyTheme(value);
                Settings.Default.IsDarkTheme = value;  // 保存用户设置
                Settings.Default.Save();
            }
        }

        /// <summary>
        /// 修改窗口主题
        /// </summary>
        /// <param name="isDarkTheme">true=深色，false=浅色</param>
        private static void ModifyTheme(bool isDarkTheme)
        {
            var paletteHelper = new PaletteHelper();
            var theme = paletteHelper.GetTheme();
            theme.SetBaseTheme(isDarkTheme ? Theme.Dark : Theme.Light);
            paletteHelper.SetTheme(theme);
        }

        private bool _isShowMovePoint; // 是否显示棋子的可移动点标识
        public bool IsShowMovePoint
        {
            get { return _isShowMovePoint; }
            set
            {
                SetProperty(ref _isShowMovePoint, value); 
                Settings.Default.IsShowMovePoint = value;
                Settings.Default.Save();
            }
        }

    }
}
